﻿using RestSharp;

namespace Huasky.Rest;

/// <summary>
/// 远程请求
/// </summary>
public static class RestHelper
{
    private static RestClient client;

    static RestHelper()
    {
        client = new RestClient("http://localhost:5178");
    }

    public static async Task<string> GetNameAsync()
    {
        var response = await client.GetJsonAsync<string>("/home/name");
        return response;
    }

    public static async Task<Student> CreateStudentAsync(Student stu)
    {
        var request = new RestRequest("/student/create").AddBody(stu);
        return await client.PostAsync<Student>(request);
    }

    public static async Task<List<Student>> GetStudentListAsync()
    {
        return await client.GetJsonAsync<List<Student>>("/student/list");
    }

    public static async Task<Student> GetStudentAsync(int id)
    {
        var request = new RestRequest("/student/get/" + id).AddHeader("Authentication", "sunxiaoshuangzaiwuhan");
        return await client.GetAsync<Student>(request);
    }

}
